home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / wptools1 / vcl / wpspdlg1.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  3KB  |  140 lines

  1. unit Wpspdlg1;
  2. { SpellDialog ---------------------------------
  3.   TextProcessor for Delphi
  4.   CopyRight 1996 by Julian Ziersch Software, Mⁿnchen
  5.  
  6.   This unit demonstrates how to use the spelling interface
  7.   functions of WPRichText.
  8.   --------------------------------------------- }
  9.  
  10. interface
  11.  
  12. uses
  13.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  14.   Forms, Dialogs, StdCtrls, Buttons, WPWinCtr;
  15.  
  16. type
  17.   TWPSpDialog = class(TForm)        
  18.     WordList: TListBox;
  19.     Word: TEdit;
  20.     ReplaceAs: TEdit;
  21.     Ignore: TBitBtn;
  22.     Replace: TBitBtn;
  23.     Cancel: TBitBtn;
  24.     procedure IgnoreClick(Sender: TObject);
  25.     procedure ReplaceClick(Sender: TObject);
  26.     procedure CancelClick(Sender: TObject);
  27.     procedure FormShow(Sender: TObject);
  28.   private
  29.     { Private-Deklarationen }
  30.     fsFirstCall : Boolean;
  31.     fsEditBox   : TWPCustomRtfEdit;
  32.     procedure SetEditBox(x : TWPCustomRtfEdit);
  33.   public
  34.     { Public-Deklarationen }
  35.     property EditBox : TWPCustomRtfEdit read fsEditBox write SetEditBox;
  36.   end;
  37.  
  38. TWPSpellCheckDlg = class(TComponent)
  39. private
  40.   dia       : TWPSpDialog;
  41.   fsEditBox : TWPCustomRtfEdit;
  42. public
  43.   destructor  Destroy; override;
  44.   procedure Execute;
  45. published
  46.   property EditBox : TWPCustomRtfEdit read fsEditBox write fsEditBox;
  47. end;
  48.  
  49. var
  50.   WPSpDialog: TWPSpDialog;
  51.  
  52. implementation
  53.  
  54. {$R *.DFM}
  55.  
  56. destructor TWPSpellCheckDlg.Destroy;
  57. begin
  58.   if dia<>nil then
  59.   begin
  60.         if dia.visible then dia.Close;
  61.         dia.Free;
  62.   end;
  63.   inherited Destroy;
  64. end;
  65.  
  66. procedure TWPSpellCheckDlg.Execute;  { Will not free the Dialogbox because it is nnon modal ! }
  67. begin
  68.  if assigned(fsEditBox) then
  69.  begin
  70.    if dia=nil then dia := TWPSpDialog.Create(Self);
  71.    dia.EditBox := fsEditBox;
  72.    fsEditBox.Spell_FromCursorPos;
  73.    dia.Show;
  74.  end;
  75. end;
  76.  
  77. procedure TWPSpDialog.SetEditBox(x : TWPCustomRtfEdit);
  78. begin
  79.   fsEditBox := x;
  80.   if x<>nil then x.Spell_FromCursorPos;
  81. end;
  82.  
  83.  
  84. procedure TWPSpDialog.IgnoreClick(Sender: TObject);
  85. var
  86.  s : String;
  87. begin
  88.  while TRUE do
  89.  begin
  90.   EditBox.Spell_FromCursorPos;
  91.   s := EditBox.Spell_GetNextWord;
  92.   if s='' then break;
  93.   { test Dictionary .... ################################
  94.     if not InDictionary(s) then
  95.     begin
  96.        EditBox.Spell_SelectWord;
  97.        WordList.Strings.Assign( GuessList );
  98.        break;
  99.     end
  100.     else continue;
  101.     ##################################################### }
  102.    { without a dictonary any word is unknown: }
  103.       EditBox.Spell_SelectWord;
  104.       break;
  105.  end;
  106.  Word.Text      := s;
  107.  ReplaceAs.Text := s;
  108.  if (s='') and (fsFirstCall=FALSE) then close;
  109. end;
  110.  
  111. { Replace will replace the selected Text.
  112.   If you use the procedure
  113.   EditBox.Spell_ReplaceWord(s : string) the replacment will be done
  114.   invisibly.
  115.   If you have a non modal spell dialog, the use of Spell_ReplaceWord might
  116.   cause errors if the user has changed the text meanwhile.
  117. }
  118.  
  119. procedure TWPSpDialog.ReplaceClick(Sender: TObject);
  120. begin
  121.   if CompareStr(EditBox.SelText,Word.Text)=0 then  { Replace selceted Text }
  122.      EditBox.SelText := ReplaceAs.Text;
  123.   IgnoreClick(Sender);
  124. end;
  125.  
  126. procedure TWPSpDialog.CancelClick(Sender: TObject);
  127. begin
  128.   EditBox.Spell_FromCursorPos;
  129.   Close;
  130. end;
  131.  
  132. procedure TWPSpDialog.FormShow(Sender: TObject);
  133. begin
  134.   fsFirstCall := TRUE;
  135.   IgnoreClick(Sender);
  136.   fsFirstCall := FALSE;
  137. end;
  138.  
  139. end.
  140.